[SQL]Summing a column while ignoring duplicate records(row_number())


SELECT custid, SUM(amount)
FROM (SELECT t.*,
             ROW_NUMBER() OVER (PARTITION BY custid, transid ORDER BY transid) AS seqnum
      FROM table_1 t
     ) t
WHERE seqnum = 1;
#SQL






你可能感興趣的文章

進入 Vue.js 前的 ES6 必備知識

進入 Vue.js 前的 ES6 必備知識

Linkedin  Java 檢定題庫 static import

Linkedin Java 檢定題庫 static import

Commend Line 速記

Commend Line 速記






留言討論